package com.ruoyi.system.vo.weishuapay;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Controller;

@Controller
public class ReadExcelTools {


	public static List<RegionBean> regionList = new ArrayList<>();
	public static List<ProductBean> productList = new ArrayList<>();
	public static List<RegionBean> regionListKFT = new ArrayList<>();
	public static List<RegionBean> regionListhd = new ArrayList<>();
	
	public static List<ProductBean> productListYX = new ArrayList<>();
	public static List<RegionBean> regionListKFTYX = new ArrayList<>();
	
	public static Set<String> provicesKFT = new HashSet<>();//省份
	public static Set<String> citysKFT = new HashSet<>();//城市
	public static Set<String> distKFT = new HashSet<>();//区域

	static {
		loadKFT();
		loadWeishua();
	}
	
	public static void main(String[] args) {
	}
	
	
	
	
	
	
	public static void loadKFT() {
		URL resource = ReadExcelTools.class.getResource("/kftcitys.xls");
		File excelFile = new File(resource.getFile());
		HSSFWorkbook wb;
		try {
			wb = new HSSFWorkbook(new FileInputStream(excelFile));
			HSSFSheet sheet = wb.getSheetAt(0);
			RegionBean b = new RegionBean();
			int j = 0;
			for (Row cels : sheet) {
				j++;
				if (j < 1)
					continue;
				b = new RegionBean();
				int i = 0;
				// 0718 上海市 卢湾区 卢湾区
				for (Cell cell : cels) {
					cell.setCellType(1);// 强制设置类型为string
					String value = cell.getRichStringCellValue().getString();
					if (i == 0) {
						b.setRegionCode(value);
						b.setRegionId(value);
					}
//					if (i == 1)
//						b.setRegionName(value);
					if (i == 2)
						b.setRegionName(value);
					i++;
				}
				regionListKFT.add(b);
			}
			for(RegionBean bean : regionListKFT) {
				provicesKFT.add(bean.getRegionCode());
				citysKFT.add(bean.getRegionName());
				distKFT.add(bean.getParentId());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public static void loadhd() {
		URL resource = ReadExcelTools.class.getResource("/hdcitys.xls");
		File excelFile = new File(resource.getFile());
		HSSFWorkbook wb;
		try {
			wb = new HSSFWorkbook(new FileInputStream(excelFile));
			HSSFSheet sheet = wb.getSheetAt(0);
			RegionBean b = new RegionBean();
			int j = 0;
			for (Row cels : sheet) {
				j++;
				if (j < 1)
					continue;
				b = new RegionBean();
				int i = 0;
				// 0718 上海市 卢湾区 卢湾区
				for (Cell cell : cels) {
					cell.setCellType(1);// 强制设置类型为string
					String value = cell.getRichStringCellValue().getString();
					if (i == 0) {
						b.setRegionCode(value);
						b.setRegionId(value);
					}
//					if (i == 1)
//						b.setRegionName(value);
					if (i == 2)
						b.setRegionName(value);
					i++;
				}
				regionListhd.add(b);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void loadWeishua() {
		URL resource = ReadExcelTools.class.getResource("/region.xls");
		File excelFile = new File(resource.getFile());
		HSSFWorkbook wb;
		try {
			wb = new HSSFWorkbook(new FileInputStream(excelFile));
			HSSFSheet sheet = wb.getSheetAt(1);
			RegionBean b = new RegionBean();
			int j = 0;
			for (Row row : sheet) {
				j++;
				if (j < 5)
					continue;
				b = new RegionBean();
				int i = 0;
				for (Cell cell : row) {
					cell.setCellType(1);// 强制设置类型为string
					String string = cell.getRichStringCellValue().getString();
					if (i == 0)
						b.setRegionId(string);
					if (i == 1)
						b.setRegionCode(string);
					if (i == 2)
						b.setRegionName(string);
					if (i == 3)
						b.setParentId(string);
					if (i == 4)
						b.setRegionType(string);
					i++;
				}
				regionList.add(b);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	static {
		URL resource = ReadExcelTools.class.getResource("/region.xls");
		File excelFile = new File(resource.getFile());
		HSSFWorkbook wb;
		try {
			wb = new HSSFWorkbook(new FileInputStream(excelFile));
			HSSFSheet sheet = wb.getSheetAt(0);
			ProductBean b = new ProductBean();
			int j = 0;
			for (Row row : sheet) {
				j++;
				if (j < 2)
					continue;
				b = new ProductBean();
				int i = 0;
				for (Cell cell : row) {
					cell.setCellType(1);
					String string = cell.getRichStringCellValue().getString();
					if (i == 0)
						b.setMcc(string);
					if (i == 1)
						b.setName(string);
					i++;
				}
				productList.add(b);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
